function Can_Room()
{
	Can_Array.apply(this, [ "Room_Can" ]);
}
extend_usemid(Can_Room, Can_Array);

function Room_Info(owner)
{
	Fact_Info.apply(this, arguments);
	this.position_player = new Array();
	this.self_w = 120;
	this.self_h = 160;
	//
	this.owner = owner;
	// 
	this.ui = new Can_UI();
	//
	this.player_position = new Array();
}
extend_usemid(Room_Info, Fact_Info);

/**
 * 初始化一切绘图需要的信息
 */
Room_Info.prototype.init = function()
{
}

// ///////////////////////////
// ///////////////////////////
// ///////////////////////////
// ///////////////////////////
// ///////////////////////////

function Room_Base(a_id, a_factid, a_number, a_name)
{

	Fact_Scene.apply(this, arguments);
	// 房间顺序号
	this.room_number = a_number;
	// 用户昵称
	this.room_name = a_name;
	// 房间容纳最多人数
	this.room_size = "";
	// 房间密码
	this.room_password = null;
	// 房间类型 1v1 8人自由等等
	this.room_type = null;
	// 房间当前用户数
	this.user_amount = null;
	// 房间里的game
	this.game = new Game_Normal();
	// 静态 界面的配置
	this.view = new ViewConf_Room();
	// 外观
	this.drawable_surface = null;
	// 房间配置
	this.fact_info = new Room_Info(this);
}
extend_usemid(Room_Base, Fact_Scene);

/**
 * 主循环线程
 */
Room_Base.prototype.run = function()
{
	var _time = 1;
	var _this = this;

	this.timer = setInterval(function()
	{
		if(_this.onoff)
		{
			_this.view.draw();
		}
	}, _time);
}

/**
 * 初始化
 */
Room_Base.prototype.init = function(aContext)
{
	Fact_Scene.prototype.init.apply(this, arguments);
	// context
	this.context = aContext;
	// 卧底this
	this.intern(this.context, "room");
	// 静态界面配置与的动态数据关联
	this.view.facts.datas["data_users_nickname"].relevant(this.users);
	this.view.facts.datas["data_users"].relevant(this.users);
	this.run();
}

/**
 * 开始游戏
 */
Room_Base.prototype.startGame = function(aGame)
{
	// 关掉开关
	this.turn("off");
	this.stopInterval();
	// 清屏
	this.context.clean();
	// 先传players过去
	this.game = aGame;
	this.game.room = this;
	this.game.init(this.context);
}

/**
 * 点击事件捕获 self是canvas
 */
Room_Base.prototype.onClick = function(evt, attach)
{
	var _target_unit = this.findSelect(evt);
	var _target = _target_unit.link;
	alert("选中：" + _target["fact_id"] + " " + _target["object_type"]);

	switch (_target["object_type"])
	{
	// ui
	case 'UI_Normal':
		switch (_target["fact_id"])
		{
		case 'ui_ready':
			break;
		case 'ui_unready':
			break;
		case 'ui_startgame':
			alert("开始游戏");
			var _pro_startgame = new Pro_StartGame(this.room_number);
			this.context.send(_pro_startgame);
			break;
		default:
			break;
		}
		break;
	case 'Player_Normal':
		break;
		
		
	default:
		break;
	}
}

/**
 * onRecv
 */
Room_Base.prototype.onRecv = function(msg)
{
	Fact_Scene.prototype.onRecv.apply(this, [msg]);
	var parsed = JSON.parse(msg.data);
	alert("on Room_Base Recv:" + parsed.name + "||" + msg.data);
	switch (parsed.pro_id)
	{
	// 开始游戏
	case '5052':
		var _game = proToObj(parsed["game"]);
		this.startGame(_game);
		break;
	case 'error':
		alert("error");
		break;
	default:
		break;
	}
}

// ////////////////////////////////////////////
// ////////////////////////////////////////////
// ////////////////////////////////////////////
// ////////////////////////////////////////////

/**
 * 普通子类对象
 */
function Room_Normal(a_id, a_factid, number, name)
{
	Room_Base.apply(this, [ a_id, a_factid ]);
}
extend_usemid(Room_Normal, Room_Base);

/**
 * 临时
 * 
 * @param a_id
 * @param a_roomid
 * @param number
 * @param name
 * @returns
 */
function Room_Eight(a_id, a_roomid, number, name)
{
	Room_Base.apply(this, [ a_id, a_roomid, number, name ]);
	this.room_type = "8_freedom";
	this.room_size = 5;
	// 图片路径
	this.imagesrc = 'media/images/room.jpg';
	this.position = new Position_Normal(10 + number * 145, 20, 120, 160);
	this.addDrawRescource(name, number);
}
extend_usemid(Room_Eight, Room_Base);

// ////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////

function Draw_Room(rooms)
{
	for ( var i = 0, l = rooms.length; i < l; i++)
	{
		rooms[i].drawSelf();
	}
}
